package com.zjitc;

import javax.sql.DataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/8 16:46
 * @description:
 */
@SuppressWarnings("ALL")
@Configuration
@Import(DataSourceConfig.class)
//@MapperScan("classpath:com/zjitc/Mapper/*Mapper.xml")
public class SpringMybatisXmlConfig {

  //已崩溃！！！！！！！！！！！！！！！！

  @Bean(name = "SqlSessionFactory")
  public SqlSessionFactoryBean createSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(dataSource);
    //FileSystemResource
    //    ClassPathResource
    factoryBean.setMapperLocations(new Resource[]{
        new FileSystemResource("D:\\Company_Spring\\Company_Spring\\demo04-spring4\\target\\classes\\com\\zjitc\\Mapper\\UserMapper.xml")
    });
    return factoryBean;
  }

  @Bean
  public MapperScannerConfigurer mapperScanner(){
    MapperScannerConfigurer MSC= new MapperScannerConfigurer();
    MSC.setBasePackage("com.zjitc.Mapper");
    MSC.setSqlSessionFactoryBeanName("SqlSessionFactory");
    return MSC;
  }

}
